package com.lanyun.serviceimpl;

import com.lanyun.dao.DeptDao;
import com.lanyun.pojo.Dept;
import com.lanyun.pojo.Emp;
import com.lanyun.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptDao deptDao;
    @Override
    public List<Dept> getAll() {
        return deptDao.getAll();
    }

    @Override
    public Integer insertDept(Dept dept) {
        return deptDao.createDept(dept);
    }

    @Override
    public Integer deleteDept(Integer id) {
        return deptDao.deleteDeptById(id);
    }

    @Override
    public Integer deleteSomeDept(String ids) {
        String id = ids.substring(0,ids.length()-1);
        String [] array = id.split(",");
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < array.length; i++) {
            list.add(Integer.parseInt(array[i]));
        }
        return deptDao.deleteSomeDeptById(list);
    }

    @Override
    public Dept findDept_update(Integer id) {
        return deptDao.find_update(id);
    }

    @Override
    public Integer updateDept(Dept dept) {
        return deptDao.deptUpdate(dept);
    }
}